﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace MaiPlanServer.IRepository
{
    public interface IBaseRepository
    {
        #region 异步

        /// <summary>
        /// 根据条件查询第一条数据
        /// 例：Select * from Table Where Id =@Id  Param： new{Id=1}
        /// </summary>
        /// <param name="Sql"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        public Task<T> QueryFirstOrDefaultAsync<T>(string Sql, object Param) where T : class;
        public Task<T> QueryFirstOrDefaultAsync<T>(string Sql) where T : class;

        /// <summary>
        /// 查询所有数据
        /// </summary>
        /// <param name="Sql"></param>
        /// <returns></returns>
        public Task<IEnumerable<T>> QueryAllAsync<T>(string Sql) where T : class;
        /// <summary>
        /// 根据条件查询所有
        /// </summary>
        /// <param name="Sql"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        public Task<IEnumerable<T>> QueryAsync<T>(string Sql, object Param) where T : class;


        /// <summary>
        /// 插入单条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Task<bool> InsertAsync<T>(T model) where T : class;
        public Task<bool> InsertAsync(string Sql, object Param);

        /// <summary>
        /// 批量插入数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public Task<bool> InsertAsync<T>(IEnumerable<T> list) where T : class;


        /// <summary>
        /// 删除一条数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Task<bool> DeleteAsync<T>(T model) where T : class;


        /// <summary>
        /// 根据主键 批量删除
        /// </summary>
        /// <param name="Ids"></param>
        /// <returns></returns>
        public Task<bool> DeleteAsync(string Sql, object Param);

        /// <summary>
        /// 批量删除数据
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public Task<bool> DeleteAsync<T>(IEnumerable<T> list) where T : class;


        /// <summary>
        /// 获取总条数
        /// </summary>
        /// <param name="Sql"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        public Task<int> GetRecoreCountAsync(string Sql,object Param);
        /// <summary>
        /// 获取总条数
        /// </summary>
        /// <param name="Sql"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        public Task<int> GetRecoreCountAsync(string Sql);



        public Task<bool> UpdateAsync(string sql,object Param);
        /// <summary>
        /// 事务修改
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="Param"></param>
        /// <returns></returns>
        public Task<bool> UpdateTranAsync(string sql, object Param);
        public  Task<bool> UpdateAsync<T>(T model) where T : class;
        public  Task<bool> UpdateAsync<TKey, T>(T model, TKey key) where T : class;

        /// <summary>
        /// 事务级联更新 注意：会先清除所有该单据子项数据在进行新增
        /// </summary>
        /// <typeparam name="T2"></typeparam>
        /// <param name="model"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public Task<bool> UpdateTranAsync<T,T2>(T model, IEnumerable<T2> list) where T : class;


        /// <summary>
        /// 使用事务执行  新增两张表数据，其中 表二是批量的
        /// </summary>
        /// <typeparam name="T2"></typeparam>
        /// <param name="model"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public Task<bool> InsertTranAsync<T,T2>(T model, IEnumerable<T2> list) where T : class;

        #endregion
    }
}
